package com.example.guethe.fireanalysisapp.base;

import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.TextView;


import com.example.guethe.fireanalysisapp.R;


import butterknife.BindView;
import cn.droidlover.xdroidmvp.mvp.XActivity;

/**
 * Created by zhaoshengping on 2017/8/14.
 */

 public abstract class BaseActivity extends XActivity
        implements NavigationView.OnNavigationItemSelectedListener{

//    //顶栏
//    @BindView(R.id.toolbar)
//    public Toolbar toolbar;
//
//    //打开侧边栏的图标
//    @BindView(R.id.drawer_layout)
//    public DrawerLayout drawer;

    //侧边栏
    @BindView(R.id.nav_view)
    public NavigationView navigationView;

//    //顶栏标题
//    @BindView(R.id.tv_title)
//    public TextView tv_title;


//    //设置标题
//    public void setTitle (String title) {
//        if (this.tv_title == null) {
//            this.tv_title = (TextView) findViewById(R.id.tv_title);
//            if (this.tv_title == null) {
//                return;
//            }
//        }
//        this.tv_title.setText(title);
//    }




    @Override
    public void initData(Bundle savedInstanceState){

        //去掉toolbar默认标题
        android.support.v7.app.ActionBar actionBar = getSupportActionBar();
        if (actionBar != null){
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowTitleEnabled(false);
        }

//        //点击打开侧边栏按钮的转动效果
//        if(drawer==null||toolbar==null){
//            this.drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
//            this.toolbar = (Toolbar) findViewById(R.id.toolbar);
//            if (drawer==null||toolbar==null) {
//                return;
//            }
//        }
//        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
//                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
//        drawer.addDrawerListener(toggle);
//        toggle.syncState();


        //设置点击事件
        if(this.navigationView==null){
            this.navigationView = (NavigationView) findViewById(R.id.nav_view);
            if(this.navigationView==null)
                return;
        }
        navigationView.setNavigationItemSelectedListener(this);

    }


    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.;
        int id = item.getItemId();

        if (id == R.id.nav_index) {
            // Handle the camera action
        } else if (id == R.id.nav_list) {

        } else if (id == R.id.nav_map) {

        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}
